import 'package:flutter/material.dart';
import 'package:flutter_component_tool/flutter_components_tools.dart';

/// 星期几数据源
const List<String> _weeks = ["日", "一", "二", "三", "四", "五", "六"];

/// 星期
class WeekWidget extends StatelessWidget {
  /// 视图高度
  final double height;

  /// 视图背景颜色
  final Color bgColor;

  /// 周末两天文本 style
  final TextStyle restDayStyle;

  /// 一...五颜色文本 style
  final TextStyle weekdayStyle;

  const WeekWidget({
    super.key,
    this.height = 44,
    this.bgColor = Colors.white,
    this.restDayStyle = const TextStyle(
      color: Colors.grey,
      fontSize: 13,
      fontWeight: FontWeight.bold,
    ),
    this.weekdayStyle = const TextStyle(
      color: Colors.black,
      fontSize: 13,
      fontWeight: FontWeight.bold,
    ),
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: height,
      color: bgColor,
      child: ListView(
        scrollDirection: Axis.horizontal,
        children: [
          for (int i = 0; i < _weeks.length; i++)
            if (i == 0 || i == _weeks.length - 1)
              _WeekdayWidget(
                value: _weeks[i],
                textStyle: restDayStyle,
              )
            else
              _WeekdayWidget(
                value: _weeks[i],
                textStyle: weekdayStyle,
              )
        ],
      ),
    );
  }
}

/// 星期几
class _WeekdayWidget extends StatelessWidget {
  /// 星期几
  final String value;

  /// 文本样式
  final TextStyle? textStyle;

  const _WeekdayWidget({
    Key? key,
    required this.value,
    this.textStyle,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width / 7,
      alignment: Alignment.center,
      child: Text(
        value,
        style: textStyle,
      ),
    );
  }
}
